package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportOperateLog;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportOperateLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2019-05-18 20:14:24
 */
public class TransportOperateLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportOperateLogConverts.class);

    public static List<TransportOperateLogDTO> convert(List<TransportOperateLog> transportOperateLogList) {
        if (CollectionUtils.isEmpty(transportOperateLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportOperateLogDTO> transportOperateLogListResult = Lists.newArrayList();
        for (TransportOperateLog transportOperateLog : transportOperateLogList) {
            transportOperateLogListResult.add(convert(transportOperateLog));
        }
        return transportOperateLogListResult;
    }

    public static TransportOperateLogDTO convert(TransportOperateLog transportOperateLog) {
        try {
            return BeanUtils.copy(transportOperateLog, TransportOperateLogDTO.class);
        } catch (Exception e) {
            LOG.error("TransportOperateLog到TransportOperateLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportOperateLog到TransportOperateLogDTO转换失败", e);
        }
    }

    public static TransportOperateLog convert(TransportOperateLogDTO transportOperateLogDTO) {
        try {
            return BeanUtils.copy(transportOperateLogDTO, TransportOperateLog.class);
        } catch (Exception e) {
            LOG.error("TransportOperateLogDTO到TransportOperateLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportOperateLogDTO到TransportOperateLog转换失败", e);
        }
    }
}